//
//  UIBarButtonItem+Extension.m
//  SinaWeiboOC
//
//  Created by hgj on 2016/11/29.
//  Copyright © 2016年 HuGuoJian. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"

@implementation UIBarButtonItem (Extension)

- (instancetype)initWithTitle:(NSString *)title Image:(NSString *)imageName style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action {
    
    UIButton *btn = [[UIButton alloc] init];
    
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
    
    UIImage *image = [UIImage imageNamed:imageName];
    [btn setImage:image forState:UIControlStateNormal];
    
    [btn sizeToFit];
    
//    if ([self respondsToSelector:@selector(action)]) {
        [btn addTarget:target action:@selector(action) forControlEvents:UIControlEventTouchUpInside];
//    }
    
    self.customView = btn;
    return self;
}

@end
